home *** CD-ROM | disk | FTP | other *** search
/ Nebula 1 / Nebula One.iso / Communications / pcomm / Source / s_menu.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-06-12  |  3.2 KB  |  156 lines

  1. /*
  2.  * Display the setup menu, prompts for a bunch of other menus.  A non-zero
  3.  * return code means we have to restart the input routine.
  4.  */
  5.  
  6. #include <stdio.h>
  7. #include <curses.h>
  8. #include "config.h"
  9. #include "misc.h"
  10.  
  11. int
  12. setup_menu()
  13. {
  14.     extern int fd, xmc;
  15.     WINDOW *s_win, *newwin();
  16.     char *ans, *get_str();
  17.     int ret_code;
  18.     static int param_flag = 0, modem_flag = 0, ext_flag = 0;
  19.     static void top_line();
  20.  
  21.     s_win = newwin(23, 80, 0, 0);
  22.  
  23.     top_line(s_win);
  24.     mvwaddstr(s_win, 3, 29, "1) TTY Setup");
  25.     mvwaddstr(s_win, 5, 29, "2) Modem Setup");
  26.     mvwaddstr(s_win, 7, 29, "3) Terminal Setup");
  27.     mvwaddstr(s_win, 9, 29, "4) General Setup");
  28.     mvwaddstr(s_win, 11, 29, "5) ASCII Transfer Setup");
  29.     mvwaddstr(s_win, 13, 29, "6) External Protocol Setup");
  30.     mvwaddstr(s_win, 15, 29, "S) Save setup to disk");
  31.     horizontal(s_win, 19, 0, 80);
  32.     mvwattrstr(s_win, 20, 0, A_BOLD, "OPTION ==> ");
  33.     mvwaddstr(s_win, 20, 58, "  Press <ESC> to exit");
  34.     wmove(s_win, 20, 12);
  35.     touchwin(s_win);
  36.     wrefresh(s_win);
  37.  
  38.     ret_code = 0;
  39.                     /* get the options */
  40.     while ((ans = get_str(s_win, 1, "123456Ss", "")) != NULL) {
  41.         if (xmc > 0) {
  42.             clear_line(s_win, 0, 0, FALSE);
  43.             wrefresh(s_win);
  44.         }
  45.         switch (*ans) {
  46.             case '1':
  47.                 if (tty_setup())
  48.                     modem_flag++;
  49.                 break;
  50.             case '2':
  51.                 if (modem_setup())
  52.                     modem_flag++;
  53.                 break;
  54.             case '3':
  55.                 /*
  56.                  * term_setup() returns a 1 if something was
  57.                  * changed, and a 2 if the change requires
  58.                  * the input routine to be restarted.
  59.                  */
  60.                 if (ret_code = term_setup()) {
  61.                     ret_code--;
  62.                     param_flag++;
  63.                 }
  64.                 break;
  65.             case '4':
  66.                 if (gen_setup())
  67.                     param_flag++;
  68.                 break;
  69.             case '5':
  70.                 if (axfer_setup())
  71.                     param_flag++;
  72.                 break;
  73.             case '6':
  74.                 if (ext_setup())
  75.                     ext_flag++;
  76.                 break;
  77.             case 's':
  78.             case 'S':
  79.                 if (xmc > 0)
  80.                     top_line(s_win);
  81.                 /*
  82.                  * Writes to disk are not critical, since
  83.                  * the changes are made in memory.
  84.                  */
  85.                 if (param_flag) {
  86.                     mvwattrstr(s_win, 22, 27, A_BLINK, "Updating Parameter File");
  87.                     wrefresh(s_win);
  88.                     wait_key(s_win, 3);
  89.                     if (up_param()) {
  90.                         touchwin(s_win);
  91.                         wrefresh(s_win);
  92.                     }
  93.                     else
  94.                         param_flag = 0;
  95.                 }
  96.                 if (modem_flag) {
  97.                     mvwattrstr(s_win, 22, 27, A_BLINK, "Updating Modem Database");
  98.                     wrefresh(s_win);
  99.                     wait_key(s_win, 3);
  100.                     if (up_modem()) {
  101.                         touchwin(s_win);
  102.                         wrefresh(s_win);
  103.                     }
  104.                     else
  105.                         modem_flag = 0;
  106.                 }
  107.                 if (ext_flag) {
  108.                     mvwattrstr(s_win, 22, 25, A_BLINK, "Updating External Protocols");
  109.                     wrefresh(s_win);
  110.                     wait_key(s_win, 3);
  111.                     if (up_extrnl()) {
  112.                         touchwin(s_win);
  113.                         wrefresh(s_win);
  114.                     }
  115.                     else
  116.                         ext_flag = 0;
  117.                 }
  118.                 clear_line(s_win, 22, 25, FALSE);
  119.                 wrefresh(s_win);
  120.                 break;
  121.             default:
  122.                 beep();
  123.         }
  124.         touchwin(s_win);
  125.         if (xmc > 0)
  126.             top_line(s_win);
  127.  
  128.         mvwaddch(s_win, 20, 12, (chtype) ' ');
  129.         wmove(s_win, 20, 12);
  130.         wrefresh(s_win);
  131.     }
  132.     if (fd == -1) {
  133.         werase(s_win);
  134.         wrefresh(s_win);
  135.     }
  136.     delwin(s_win);
  137.     return(ret_code);
  138. }
  139.  
  140. /*
  141.  * Put the top line on the window.
  142.  */
  143.  
  144. static void
  145. top_line(win)
  146. WINDOW *win;
  147. {
  148.     clear_line(win, 0, 0, FALSE);
  149.     wrefresh(win);
  150.     horizontal(win, 0, 0, 33);
  151.     mvwattrstr(win, 0, 34, A_BOLD, "Setup Menu");
  152.     horizontal(win, 0, 45, 34);
  153.     wrefresh(win);
  154.     return;
  155. }
  156.